<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<script>
			// 希尔排序
			let arr = [0, 49, 38, 65, 97, 76, 13, 27, 49];

			function sort(arr, n) {
				// debugger;
				let d, i, j;
				for (d = Math.floor(n / 2); d >= 1; d = Math.floor(d / 2)) {
					for (i = d + 1; i <= n; i++) {
						if (arr[i] < arr[i - d]) {
							arr[0] = arr[i];
							for (j = i - d; j > 0 && arr[0] < arr[j]; j -= d) {
								arr[j + d] = arr[j];
							}
							arr[j + d] = arr[0];
						}
					}
				}
				return arr;
			}
			console.log(sort(arr, arr.length));
		</script>
	</body>
</html>
